package edu.nf.controller.handler;

import edu.nf.hotel.exception.LoginException;
import edu.nf.hotel.vo.ResultVO;
import org.nf.web.annotation.ExceptionHandler;
import org.nf.web.servlet.View;
import org.nf.web.servlet.view.JsonView;

/**
 * 处理全局异常
 * @Data 2023-06-22
 * @Author Lsw
 */
public class GlobalExceptionHandler {
    /**
     * 处理登陆异常的错误
     * @return
     */
    @ExceptionHandler(LoginException.class)
    public View handleLoginException(LoginException e) {
        ResultVO vo = new ResultVO();
        vo.setCode(e.getErrorCode());
        vo.setMessage(e.getMessage());
        return new JsonView(vo);
    }

    @ExceptionHandler(RuntimeException.class)
    public View handleLoginException(RuntimeException e) {
        e.printStackTrace();
        ResultVO vo = new ResultVO();
        vo.setCode(500);
        vo.setMessage("服务器内部错误，请稍后尝试");
        return new JsonView(vo);
    }
}
